using AutoMapper;
using PowerManage.Entity.Commons;

namespace PowerManage.API.Extensions;

/// <summary>
/// AutoMapper相关扩展
/// </summary>
public static class AutoMapperExtension
{
    /// <summary>
    /// AutoMapper相关注入
    /// </summary>
    /// <param name="builder"></param>
    public static void AddPowerManageAutoMapper(this WebApplicationBuilder builder)
    {
        //AutoMapper依赖注入 手动注入 更加灵活，可以进行更细粒度的控制 公司项目为自动注入
        // 创建 AutoMapper 配置
        AutoMapper.IConfigurationProvider config = new MapperConfiguration(cfg => cfg.AddProfile<MappingProfile>());
        // 注册配置为单例
        builder.Services.AddSingleton(config);
        // 注册映射器为作用域服务
        builder.Services.AddScoped<IMapper, Mapper>();
    }
}